package no.ntnu.fp.server;

import java.io.IOException;
import java.net.ConnectException;

import no.ntnu.fp.net.co.Connection;

public class MessageReceiver implements Runnable {
	
	private Connection connection;
	private MessageListener listener;
	
	public MessageReceiver(Connection connection, 
			MessageListener listener) {
		
		this.connection = connection;
		this.listener = listener;
	}
	
	public void setListener(MessageListener listener) {
		
		this.listener = listener;
	}
	
	public void run() {
		
		while(true) {
			try {
				String message = connection.receive();
				listener.messageReceived(message);
			} 
			catch (ConnectException e) {} 
			catch (IOException e) {}
		}
	}

}
